<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>

  <body>
    <form>
      <input type="text" name="username" placeholder="请输入用户名" /><br />
      <input type="text" name="passworduuuu" placeholder="请输入密码" /><br />
      <button type="submit">登录</button>
    </form>

    <!-- 引入axios -->
    <script src="./js/axios.js"></script>
    <!-- 引入form-serialize -->
    <script src="./js/form-serialize.js"></script>
    <script>
      const form = document.querySelector('form')

      form.addEventListener('submit', function (e) {
        //阻止默认提交行为
        e.preventDefault()

        //使用serialize 默认输出查询字符串格式
        const data = serialize(this, { hash: true }) //对象
        console.log(data);

        // const data = serialize(form) //查询字符串格式 key=value&key1=value1

        //发起请求
         async function response(){
          const { data: res } = await axios.post('http://ajax-api.itheima.net/api/login', data)
          console.log(res)
        } 

        response()
        
      })
    </script>
  </body>
</html>
